package bussinessService.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import utils.DateUtil;
import module.BasicArea;
import module.BasicBanKuai;
import module.NewHouse;
import module.Shop;
import module.Unit;
import bussinessService.newHouseBussinessService;
import domain.penum.DecorationEnum;
import domain.vo.NewHouseVO;
import domain.vo.queryObject;

/**
 * 
* @ClassName: NewHouseBussinessServiceImpl 
* @Description: 房屋业务接口实现
* @author chenchao
* @date 2014年1月13日 下午5:12:48 
*
 */
public class NewHouseBussinessServiceImpl  implements newHouseBussinessService{

	/* (非 Javadoc) 
	* <p>Title: getById</p> 
	* <p>Description: </p> 
	* @param id
	* @return
	* @throws SQLException 
	* @see bussinessService.basicbussinessService#getById(java.lang.String) 
	*/ 

	public NewHouse getById(String id) throws SQLException {
		// TODO Auto-generated method stub
		return newHouseService.getById(id);
	}

	/* (非 Javadoc) 
	* <p>Title: getAll</p> 
	* <p>Description: </p> 
	* @return
	* @throws SQLException 
	* @see bussinessService.basicbussinessService#getAll() 
	*/ 

	public List<NewHouseVO> getAll() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (非 Javadoc) 
	* <p>Title: merageObject</p> 
	* <p>Description: </p> 
	* @param t
	* @throws SQLException 
	* @see bussinessService.basicbussinessService#merageObject(java.lang.Object) 
	*/ 
	
	

	public void merageObject(NewHouse t) throws SQLException {
		if(t.getId() == 0) {
			newHouseService.insertObject(t);
		} else {
			newHouseService.updateObject(t);
		}
		
	}

	/* (非 Javadoc) 
	* <p>Title: deleteT</p> 
	* <p>Description: </p> 
	* @param id
	* @throws SQLException 
	* @see bussinessService.basicbussinessService#deleteT(int) 
	*/ 
	

	public void deleteT(int id) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	/* (非 Javadoc) 
	* <p>Title: getObjectByQueryObject</p> 
	* <p>Description: </p> 
	* @param queryObject
	* @return
	* @throws SQLException 
	* @see bussinessService.basicbussinessService#getObjectByQueryObject(domain.vo.queryObject) 
	*/ 
	
	

	public List<NewHouseVO> getObjectByQueryObject(queryObject queryObject)
			throws SQLException {
		// TODO Auto-generated method stub
		List<NewHouse> results  = new ArrayList<NewHouse>();
		results =  newHouseService.getObjectByQueryObject(queryObject);
		List<NewHouseVO> vos = new ArrayList<NewHouseVO>();
		for(NewHouse nh : results) {
			NewHouseVO vo = new NewHouseVO();
			vo.setId(nh.getId());
			vo.setActualArea(nh.getActualArea());
			vo.setAddress(nh.getAddress());
			vo.setAge(nh.getAge());
			vo.setAllfloor(nh.getAllfloor());
			vo.setAllprice(nh.getAllprice());
			vo.setBalcony(nh.getBalcony());
			vo.setBlockId(nh.getBlockId());
			//获取板块名称
			BasicBanKuai bbk =  bbkService.getById(Integer.toString(nh.getBlockId()));
			vo.setBlockName((bbk != null)? bbk.getBb_name():"");
			vo.setClazz(nh.getClazz());
			vo.setCreateTime(DateUtil.date2String(nh.getCreateTime(), DateUtil.YYYY_MM_DD_HH_mm_ss));
			vo.setDecoration(DecorationEnum.getName(Integer.parseInt(nh.getDecoration())));
			vo.setDecorationId(nh.getDecoration());
			vo.setDeliveryData(nh.getDeliveryData());
			vo.setDistrictId(nh.getDistrictId());
			BasicArea ba = baService.getById(Integer.toString(nh.getDistrictId()));
			vo.setDistrictName((ba != null)?ba.getBhaName():"");
			vo.setE_name(nh.getE_name());
			vo.setE_sn(nh.getE_sn());
			vo.setEstablishment(nh.getEstablishment());
			vo.setFace(nh.getFace());
			vo.setFloor(nh.getFloor());
			vo.setGarage(nh.getGarage());
			vo.setHouseMark(nh.getHouseMark());
			vo.setHouseNumber(nh.getHouseNumber());
			vo.setKeynumber(nh.getKeynumber());
			vo.setKitchen(nh.getKitchen());
			vo.setOwner(nh.getOwner());
			vo.setOwnerMark(nh.getOwnerMark());
			vo.setOwnerName(nh.getOwnerName());
			vo.setOwnerPhone(nh.getOwnerPhone());
			vo.setOwnerType(nh.getOwnerType());
			vo.setPremises(nh.getPremises());
			vo.setPricecondition(nh.getPricecondition());
			vo.setProperty(nh.getProperty());
			vo.setRoom(nh.getRoom());
			vo.setSaleArea(nh.getSaleArea());
			Shop shop = shopService.getById(nh.getShop());
			vo.setShop(shop.getShopName());
			vo.setSource(nh.getSource());
			vo.setStatus(nh.getStatus());
			vo.setStruct(nh.getStruct());
			vo.setTing(nh.getTing());
			vo.setType(nh.getType());
			vo.setUnitId(nh.getUnitId());
			Unit unit = unitService.getById(Integer.toString(nh.getUnitId()));
			vo.setUnitName((unit == null)?"":unit.getUnitName());
			vo.setUnitprice(nh.getUnitprice());
			vo.setVisit(nh.getVisit());
			vo.setWay(nh.getWay());
			vo.setWei(nh.getWei());
			StringBuffer roomVO = new StringBuffer();
			roomVO.append(nh.getRoom());
			roomVO.append("室");
			roomVO.append(nh.getTing());
			roomVO.append("厅" );
			roomVO.append(nh.getWei());
			roomVO.append("卫");
			vo.setRoomVO(roomVO.toString());
			vo.setFloorVO(nh.getFloor() + "/" + nh.getAllfloor());
			vos.add(vo);
		}
		return vos;
	}

	/* (非 Javadoc) 
	* <p>Title: countByQueryObject</p> 
	* <p>Description: </p> 
	* @param queryObject
	* @return
	* @throws SQLException 
	* @see bussinessService.basicbussinessService#countByQueryObject(domain.vo.queryObject) 
	*/ 
	

	public int countByQueryObject(queryObject queryObject) throws SQLException {
		// TODO Auto-generated method stub
		return newHouseService.countByQueryObject(queryObject);
	}

}
